﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TLSharp;

public partial class ChallengeFriend : System.Web.UI.Page
{
    public string CookieUserName = "";
    public string CookiePassword = "";
    public string AppGuid = System.Configuration.ConfigurationSettings.AppSettings["AppGuid"];
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Text.StringBuilder ResponseText = new System.Text.StringBuilder();

        CookieUserName = Request.Cookies["TLUsername"] != null ? Request.Cookies["TLUsername"].Value : "";
        CookiePassword = Request.Cookies["TLPassword"] != null ? Request.Cookies["TLPassword"].Value : "";
        string FriendEmail = Request.Form["FriendEmail"];
        string MyName = Request.Form["YourName"];

        //test to see if the account is valid
        
        bool bValid = false;

        GetUserProfileResponse Validate = TLSharp.TouchLeagueService.GetUserProfile(CookieUserName, CookiePassword, AppGuid);

        if (Validate.ErrorCode < 0)
        {

            bValid = true;
        }

        if (bValid)
        {

            TLSharp.ChallengeNonUserResponse ThisReq = TLSharp.TouchLeagueService.ChallengeNonUser(CookieUserName, CookiePassword, AppGuid, FriendEmail, MyName);

            if (ThisReq.ResponseType  == "Success")
            {
                ResponseText.Append("<ul><li>Your friend had been notifed of your challenge.  Why don't you give them a call and let them know to expect it?</li><li><a href='default.aspx' target=_self>Back Home</a></li></ul>");

            }
        }
        else
        {
            ResponseText.Append("<ul><li>Invalid Credentials.  Make sure your TouchLeague.com settings are correct.</li><li><a href='default.aspx' target=_self>Back Home</a></li></ul>");
        }
        Response.Write(ResponseText.ToString());
        Response.End();
        
    }
}
